home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / wood.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.9 KB  |  78 lines

  1. /*
  2.  * wood.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb, Robert F. Skinner
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * wood.c,v 4.1 1994/08/09 08:03:35 explorer Exp
  17.  *
  18.  * wood.c,v
  19.  * Revision 4.1  1994/08/09  08:03:35  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:16  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:44:35  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "wood.h"
  31.  
  32. Wood *
  33. WoodCreate()
  34. {
  35.     return (Wood *)NULL;    /* No data associated with wood texture */
  36. }
  37.  
  38. /*ARGSUSED*/
  39. void
  40. WoodApply(wood, prim, ray, pos, norm, gnorm, surf)
  41. Wood *wood;
  42. Geom *prim;
  43. Ray *ray;
  44. Vector *pos, *norm, *gnorm;
  45. Surface *surf;
  46. {
  47.     Float red, grn, blu;
  48.     Float chaos, brownLayer, greenLayer;
  49.     Float perturb, brownPerturb, greenPerturb, grnPerturb;
  50.     Float t;
  51.  
  52.     chaos = Chaos(pos, 7);
  53.     t = sin(sin(8.*chaos + 7*pos->x +3.*pos->y));
  54.  
  55.     greenLayer = brownLayer = fabs(t);
  56.  
  57.     perturb = sin(40.*chaos + 50.*pos->z);
  58.     perturb = fabs(perturb);
  59.  
  60.     brownPerturb = .6*perturb + 0.3;
  61.     greenPerturb = .2*perturb + 0.8;
  62.     grnPerturb = .15*perturb + 0.85;
  63.     grn = 0.5 * pow(fabs(brownLayer), 0.3);
  64.     brownLayer = pow(0.5 * (brownLayer+1.0), 0.6) * brownPerturb;
  65.     greenLayer = pow(0.5 * (greenLayer+1.0), 0.6) * greenPerturb;
  66.  
  67.     red = (0.5*brownLayer + 0.35*greenLayer)*2.*grn;
  68.     blu = (0.25*brownLayer + 0.35*greenLayer)*2.0*grn;
  69.     grn *= max(brownLayer, greenLayer) * grnPerturb;
  70.  
  71.     surf->diff.r *= red;
  72.     surf->diff.g *= grn;
  73.     surf->diff.b *= blu;
  74.     surf->amb.r *= red;
  75.     surf->amb.g *= grn;
  76.     surf->amb.b *= blu;
  77. }
  78.